<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ page isELIgnored="false" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<link rel="stylesheet" href="<s:url value="/resources"/>/css/common.css" type="text/css" />
<link rel="stylesheet" href="<s:url value="/resources"/>/css/innerstyle.css"
	type="text/css" />

<link rel="stylesheet" type="text/css" media="screen" href="<s:url value="/resources"/>/css/cupertino/jquery-ui.custom.min.css" />
<link rel="stylesheet" href="<s:url value="/resources"/>/css/zTreeStyle/zTreeStyle.css"
	type="text/css">
<link rel="stylesheet" href="<s:url value="/resources"/>/css/zTreeStyle/demo.css"
	type="text/css">
<script type="text/javascript" src="<s:url value="/resources"/>/js/jquery-1.7.2.min.js"></script>

<script type="text/javascript"	src="<s:url value="/resources"/>/js/jquery-ui-1.8.23.custom.min.js"></script>
<script type="text/javascript"	src="<s:url value="/resources"/>/js/jquery.ztree.all-3.4.min.js"></script>
	<script type="text/javascript"	src="<s:url value="/resources"/>/js/jquery.ztree.exhide-3.4.js"></script>
<script>
	var key;
	$(function() {	
	
	$("#jz").hide();
		$("#but2").button(); 
        $("#but3").button();
		//old_data(); 	 
		$("#but1").button();
        $( "#datepicker" ).datepicker($.datepicker.regional[ "zh-CN" ]);   
        $( "#dialog-confirm" ).dialog({
            autoOpen: false,            
			resizable: false,
			height:140,
			modal: true,
			buttons: {
				"确认": function() {
				var formdata = $("#form1").serialize();  
				//alert(formdata);
				var url = "<s:url value="/"/>/jysxx/saveXtxxInfo?"+formdata;		    
		    $.post(url, function(data) {
               
		        alert(eval('(' + data + ')').msg);
		      
               window.location.href="<s:url value="/"/>/jysxx/findxtxx";
            });
					
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}
		});
		 
		
		$( "#jsrlist" ).dialog({
		    autoOpen: false,
		    modal: true
		   });
		   
		
	});

	function tj(){
	 if(document.getElementById("jsrname").value=="")
     {
       alert("请选择接收人!");
       document.getElementById("jsrname").focus();
       return false;
     }
     if(document.getElementById("xxnr").value=="")
     {
       alert("请输入消息内容!");
       document.getElementById("xxnr").focus();
       return false;
     } 
       $( "#dialog-confirm" ).dialog( "open" );
	   /* document.form1.action="<s:url value="/"/>/jysxx/saveXtxxInfo";
					document.form1.method="post";
				 document.form1.submit();*/	
				//alert("3");
	  return true;
	}
	
	
	function showjsrlist(){
		
			$( "#jsrlist" ).dialog("open");			
			$( "#jsrlist" ).dialog({
			resizable: false,
			height: 450,
		    width: 480,
			modal: true,
			buttons: {
				"确认": function() {				
				var jsrname="";
				var jsr="";
				var jsrdwname="";
			    var treeObj = $.fn.zTree.getZTreeObj("treeDemo");			     
				var nodes = treeObj.getCheckedNodes(true);
			
				for	(var i=0;i<nodes.length;i++)
					{
					if(nodes[i].isParent)
					{
						jsrdwname=nodes[i].name;
						continue;
					}
					 // alert(nodes[i].pid);
						if(jsrname=="")
						{ 
							jsrname=jsrdwname+"-"+nodes[i].name;
							jsr+=nodes[i].id;
						}
						else
						{
							jsrname+=","+jsrdwname+"-"+nodes[i].name;
							jsr+=","+nodes[i].id;
						}
					}
				//alert(jsr);
				//alert(jsrname);
				$( "#jsrname").val(jsrname); 
				$( "#jsr").val(jsr); 
				$( this ).dialog( "close" );
				},
				"返回": function() {
					$( this ).dialog( "close" );
				}
			}	
		  
		 });	 
	}
	/*搜索ztree*/
		function searchZtree(){		    
           // alert("aa");
           $("#jz").show();
             var key =  encodeURI($("#key").val());             
             var url = "<s:url value="/"/>/jysxx/findJsrList?name="+key;                    
             $.post(url,function(data) {
             $("#jz").hide();
               var zNodes = data;                              
               $.fn.zTree.init($("#treeDemo"), setting, eval('(' + zNodes + ')'));              
            });
		}
	function old_data(){
		$.ajax({
             type: "post",
             dataType:'text',
             //dataType: "json",//返回json格式的数据
             url: "<s:url value="/"/>/jysxx/findJsrList",
            success: function(data){
                 var zNodes = data;                 
                 $.fn.zTree.init($("#treeDemo"), setting, eval('(' + zNodes + ')')); 
                }  
              });
		}
		
		var setting = {
			view: {
				selectedMulti: false
			},
			check: {
				enable: true
			},
			edit: {
				enable: false,
				showRemoveBtn: false,
				showRenameBtn: false
			},
			  data: {
			simpleData: {
				enable:true,
				idKey: "id",
				pIdKey: "pid",
				rootPId: ""
			}
		},
			callback: {			    
				beforeDrag: false,
				beforeDrop: false//,
				//beforeClick: beforeClick
			
		}};
		


		function beforeDrag(treeId, treeNodes) {
			for (var i=0,l=treeNodes.length; i<l; i++) {
			    alert(treeNodes[i].pId);
				if (treeNodes[i].drag === false) {
					return false;
				}
			}
			return true;
		}
		function beforeDrop(treeId, treeNodes, targetNode, moveType) {
		    //alert(treeNodes[0].name);
			return targetNode ? targetNode.drop !== false : true;
		}

			
		function beforeClick(treeId, treeNode) {
			if (treeNode.isParent) {
				return false;
			} else {
				//alert("这个 Demo 是用来测试 展开 / 折叠 的...\n\n去点击父节点吧... ");
				return true;
			}
		}
		
	
	</script>
</head>

<body>
	<div id="best1">
		<h2>
			<span>发送消息</span>
		</h2>
		<form id="form1" method="post">
			<table id="list_search" cellpadding="0" cellspacing="0" border="0"
				class="content_gridview">
				<tr>
					<td>

						<table cellpadding="0" cellspacing="0" border="0"
							class="content_gridview">
							<tr>
								<td style="vertical-align:middle" width="150px">接收人:<br><img src="<s:url value="/resources"/>/images/plus.jpg" width="30px" height="20px" onClick="showjsrlist();" style="vertical-align:middle"/>
						</td>
								<td align="left"  ><textarea cols="90" rows="6" id="jsrname"
										class="textarea" name="bb" readonly="readonly" style="width:100%"
										></textarea> <input 
									id="jsr" cols="90" rows="6" name="aa" type="hidden">
								</textarea></td>
							</tr>
							<tr>
								<td style="vertical-align:middle">信息内容:</td>
								<td  ><textarea cols="90" rows="10" class="textarea" style="width:100%"  id="xxnr"
										name="cc"></textarea></td>
							</tr>


						</table></td>
				</tr>

				<tr>
				  <td colspan="4" align="center"><input id="but1" type="button"
						name="" value="发送" onClick="tj();" />
						&nbsp;&nbsp;<input id="but2" type="button"
						value="返回"  onclick= "window.location.href='/mtjyqt/jysxx/findxtxx'"/></td>
				</tr>
			</table>
		</form>
	</div>
	<div id="jsrlist" title="接收人">
		<div >
		
			<div class="zTreeDemoBackground left" style="height:300px;">
			  <ul class="list">
          <li class="title"> 企业名称：<input type="text" id="key" type="text" style="width:200px;"  value="请输入企业名称查询"/>  <a id="menuBtn" href="#" onClick="searchZtree();">查询</a>
	   <div id="jz">加载中...</div>
		</li>
        </ul>
         			
		
				<ul id="treeDemo" class="ztree" style="height:280px;"></ul>
			</div>
		</div>
	</div>
	<div id="dialog-confirm" title="是否确认发送？"></div>
</body>
</html>
